package com.hiwhitley.himei.module.me;

import android.app.AlertDialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;

import com.hiwhitley.himei.R;

/**
 * Created by hiwhitley on 2016/10/11.
 */

public class MeAboutFragment extends PreferenceFragment implements Preference.OnPreferenceClickListener{
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preference);
        findPreference("license").setOnPreferenceClickListener(this);
        findPreference("email").setOnPreferenceClickListener(this);
        findPreference("github").setOnPreferenceClickListener(this);
    }

    @Override
    public boolean onPreferenceClick(final Preference preference) {
        final ClipboardManager cm =
                (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
        switch (preference.getKey()) {
            case "license":
//                new LicensesDialog.Builder(getActivity()).
//                        setNotices(R.raw.notices).setIncludeOwnLicense(true).
//                        build().showAppCompat();
//                break;
            default:
                new AlertDialog.Builder(getActivity())
                        .setMessage("复制到剪贴板？")
                        .setPositiveButton("确定", (dialogInterface, i) -> {
                            ClipData myClip;
                            CharSequence text = preference.getSummary();
                            myClip = ClipData.newPlainText("text", text);
                            cm.setPrimaryClip(myClip);
                        })
                        .setNegativeButton("取消", (dialogInterface, i) -> {
                            dialogInterface.cancel();
                        }).show();
                break;
        }
        return true;

    }
}
